<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" isELIgnored="false"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<base href="<%=basePath%>">
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8" />
	<title>常德快贷平台</title>
	<link rel="stylesheet" href="css/bootstrap.min.css" />
	<link rel="stylesheet" href="css/style1.css" />
	<link rel="stylesheet" href="css/kkpager_blue1.css" />
	<link rel="stylesheet" href="css/jjalert.css" />
	<script src="js/jquery.min.js"></script>
	<script src="js/bootstrap.min.js"></script>
	<script src="js/schedule.js" ></script>
	<script src="js/main1.js" ></script>
	<script src="js/jjalert.js" ></script>
	<style>
	.public_container .leftbar_container a.active:nth-child(3) {
	  background: url(images/my_left_bar_icon_3_new_blue.png) no-repeat 10px center;
	}
	.public_container .leftbar_container a:nth-child(3) {
	  background: url(images/my_left_bar_icon_3_new.png) no-repeat 10px center;
	}
	.public_container .leftbar_container a:nth-child(3):hover {
	  color: #0048b3;
	  font-size: 14px;
	  background: url(images/my_left_bar_icon_3_new_blue.png) no-repeat 10px center;
	  border-left: 4px solid #0048b3;
	}
</style>
<script type="text/javascript">
function loadSelect(index){
	//先清空选项
//     $.ajax({
//         url : ,
//         type : "get",
//         dataType : "json",
//         async : true,
//         data :,
//         success : function(res) {

//         },
//         error:function(data) {
//             return 'error';
//         }
//   });
}
// $(document).ready(function(){
// 	loadSelect('0');
// })
</script>
</head>
<body>
	<div class="public_container">
		
		<div class="nav_container">
			<a href="javascript:void(0)" id="xitongguanli">
				<div class="circle"></div>
				<span>系统管理</span>				
			</a> 
		<%-- <%@ include file="pageHeader2.jsp" %> --%>
		</div>
		<div class="main_container">
			<div class="leftbar_container">
				<a class="active" href="role/account_manage">账号管理</a>
				<a href="role/account_add">添加账号</a>
				<a href="role/account_rolemanage">角色管理</a>
				<a href="role/my_account" class="my_account">我的账户</a>
				<a  href="role/account_userAction" class="userAction">用户行为</a>
			</div>
			<div class="right_main_container">
				<div class="top_box">
					<div class="input_row form-group">
						<label>姓名</label>
						<input class="single form-control" type="text" id="name"/>
					</div>
					<div class="input_row flex_input" id="date_row">
						<label>创建时间</label>
						<input class="pair _1 form-control" type="text" id="calendar_input_1" />
						<div id="calendar_date_1" class="schedule-box _1"></div>
						<span>至</span>
						<input class="pair _2 form-control" type="text" id="calendar_input_2" />
						<div id="calendar_date_2" class="schedule-box _2"></div>
					</div>
					<div class="input_row form-group">
						<label>状态</label>
						<select class="single form-control" id="state">
							<option value="all">全部</option>
							<option value="0">注销</option>
							<option value="1">启用</option>
						</select>
					</div>
					<div class="input_row">
						<a href="javascript:;" class="btn btn-default search_btn">查询</a>
						<input type="text" id="account_temp" style="display:none">
					</div>
				</div>
				<div class="middle_box">
					<div class="table_container">
						<table class="table table-bordered">
							<thead>
								<tr>
									<th>序号</th>
									<th>账号</th>
									<th>姓名</th>
									<th>角色</th>
									<th>创建时间</th>
									<th>是否启用</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody id="ActionShowTable">
							</tbody>
						</table>
					</div>
					<div class="index_qyhxlistnrleftnr" style="height: 60px;padding:12px 40px;"> 
				      		<div id="kkpager">
								<span class="pageBtnWrap">
									<span class="totalText" style="line-height:30px">总数：
										<span class="currPageNum" id="companyTotalRecords">--</span>
									</span>
								    <span id="companyFirstPage"><span class="disabled">首页</span></span>
						    		<span id="companyPreviouePage"><span class="disabled">上页</span></span>
									<span id="companyPageIndexList"></span>
									<span id="companyNextPage"><span class="disabled">下页</span></span>
									<span id="companyLastPage"><span class="disabled">尾页</span></span>
								</span>
								<span class="infoTextAndGoPageBtnWrap">
									
									<span>
										<a href="javascript:void(0)" onclick="toInputPage()">转到</a>
									</span>
									<span class="goPageBox" style="">&nbsp;
										 <span id="kkpager_gopage_wrap">
										 	<input type="text" class="kkpager_btn_go_input"  value="" id='inputPageIndex' style="height:18px">
										 </span>页
									</span>
									<span class="totalText" style="line-height:30px">共<span class="currPageNum" id="companyTotalPages">--</span>页</span>
							    </span>	
				      		</div> 
				    	</div> 
				</div>
			</div>
		</div>		
	</div>
	<!-- 密码重置弹框 -->
	<div class="modal fade loan_modal simple_modal" id="myalert" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	    <div class="modal-dialog">
	        <div class="modal-content">
	            <div class="modal-body">	            	
	            	<p class="text">是否重置密码？</p>
	            	<!-- 重置成功后P里面显示如下，然后按钮变成一个确定 -->
	            	<!--<p class="text">密码重置成功，新密码为123456</p>-->
	            	<div class="foot">
	            		<a href="javscript:void(0);" class="btn btn-default _1 passsure1">确定</a>
	            		<a href="javscript:;" class="btn btn-default _2" data-dismiss="modal">取消</a>
	            	</div>
	            </div>
	        </div>
	    </div>
	</div>
<script type="text/javascript">
var context = "<%=request.getContextPath()%>";
window.onload=function(){
	submit(1);
	$(".search_btn").click(function(){
		submit(1);
	});
	
	$(".passsure1").click(function(){	//重置密码的操作
		 $.ajax({
				url : "<%=request.getContextPath()%>"
				+ '/role/resetPass?account='+$("#account_temp").val()+"&newpass='000000'&fresh="+Math.random(),
				type : "get",
				contentType : "application/json",
				async : false,
				success : function(data) {
					if(data.responseText == 'success'){
						jjalert("密码重置成功");
					}
					if(data.responseText == 'error'){
						jjalert("密码重置失败");
					}
					$("#myalert").modal("hide");
				},
				error:function(data) {
					if(data.responseText == 'success'){
						jjalert("密码重置成功");
					}
					if(data.responseText == 'error'){
						jjalert("密码重置失败");
					}
					$("#myalert").modal("hide");
				}
				});
	});
	
};
//注销账号
function cancel_method(account,state){
	$.ajax({
		url : "<%=request.getContextPath()%>"
		+ '/role/cancelAccount?account='+account+"&state="+state+"&fresh="+Math.random(),
		type : "get",
		dataType : "json",
		async : false,
		success : function(data) {
			submit(1);
		},
		error:function(data) {
			submit(1);
		}
		});
}
//修改账号信息
function update_method(account){
	var path="<%=request.getContextPath()%>";
	window.location.href= path+"/role/showAccount?account="+account;
}
function submit(current){
	var name = $("#name").val();
	var role_id = $("#role").val();
	var pagesize=8;
	var sdate = $("#calendar_input_1").val();
	var edate = $("#calendar_input_2").val();
	if(sdate>edate){
		jjalert("开始时间不能晚于结束时间!");
		$("#calendar_input_1").val('');
		$("#calendar_input_2").val('');
		return;
	}
	var state = $("#state").val();
	var data ={
			'name' : encodeURI(encodeURI(name)),
			'role' : role_id,
			'sdate' : sdate,
			'edate' : edate,
			'state' : state,
			'page' : current,
			'pagesize' : pagesize,
			'fresh':Math.random()
	};
	console.log(data);
	 $.ajax({
			url : "<%=request.getContextPath()%>"
			+ '/role/showUser',
			data : data,
			type : "get",
			contentType : "application/json",
			dataType : "json",
			async : false,
			success : function(reval) {
				//console.log(data);
				var data=JSON.parse(reval);
				var total=data.totalnum;
				var pageSize=pagesize;
				var pageOnclickHtml="";
				
				var totalpage=total%pageSize==0?total/pageSize:parseInt(total/pageSize)+1;
				var totalPages=totalpage;
				var pageDisplayNum=(totalPages>8?5:2);
				if (current - 1 > 0) {
	 				$("#companyPreviouePage").html("<a href=\"javascript:void(0)\" onclick=\"toSpecficPage(" + (current - 1) +")\">上页</a>");
	 				$("#companyFirstPage").html("<a href=\"javascript:void(0)\" onclick=\"toSpecficPage(1)\">首页</a>");
	 			} else {
	 				$("#companyPreviouePage").html("<span class=\"disabled\">上页</span>");
	 				$("#companyFirstPage").html("<span class=\"disabled\">首页</span>");
	 			}
				//下一页,尾页
	 			if (current + 1 <= totalPages) {
	 				$("#companyNextPage").html("<a href=\"javascript:void(0)\" onclick=\"toSpecficPage(" + (current + 1) +")\">下页</a>");
	 				$("#companyLastPage").html("<a href=\"javascript:void(0)\" onclick=\"toSpecficPage(" + totalPages +")\">尾页</a>");
	 			} else {
	 				$("#companyNextPage").html("<span class=\"disabled\">下页</span>");
	 				$("#companyLastPage").html("<span class=\"disabled\">尾页</span>");
	 			}
				if (totalPages > 5 && current <= totalPages) {
	 				//后面剩余数量多于前面
	 				if (totalPages - (current + pageDisplayNum - 1) >= current - 1) {
	 					pageOnclickHtml += "<span><a class=\"currL\" href=\"javascript:void(0)\"  onclick=\"toSpecficPage(" + current +")\">" +current + "</a></span>"
	 					for (var i = current + 1 ; i < current + pageDisplayNum; i++) {
	 						pageOnclickHtml += "<span><a href=\"javascript:void(0)\"  onclick=\"toSpecficPage(" + i +")\">" +i + "</a></span>&nbsp;";
	 					}
	 					pageOnclickHtml += "<span><a href=\"javascript:void(0)\">" +"…" + "</a></span>&nbsp;";
	 				} else {
	 					pageOnclickHtml += "<span><a href=\"javascript:void(0)\">" +"…" + "</a></span>&nbsp;";
	 					for (var i = current - pageDisplayNum + 1 ; i < current; i++) {
	 						pageOnclickHtml += "<span><a href=\"javascript:void(0)\"  onclick=\"toSpecficPage(" + i +")\">" +i + "</a></span>&nbsp;";
	 					}
	 					pageOnclickHtml += "<span><a class=\"currL\" href=\"javascript:void(0)\"  onclick=\"toSpecficPage(" +current +")\">" +current + "</a></span>"
	 				}
	 			} else {
	 				//显示全部
	 				for (var i = 1; i <= totalPages; i++) {
	 					if (i ==current) {
	 						pageOnclickHtml += "<span><a class=\"currL\" href=\"javascript:void(0)\"  onclick=\"toSpecficPage(" +i +")\">" +i + "</a></span>";
	 						continue;
	 					}
	 					pageOnclickHtml += "<span><a href=\"javascript:void(0)\"  onclick=\"toSpecficPage(" +i +")\">" +i + "</a></span>";
	 				}
	 			}
				$("#companyPageIndexList").html(pageOnclickHtml);
				$("#companyTotalRecords").text(total);
				$("#companyTotalPages").text(totalpage);
				$("#ActionShowTable").html("");
				var tableContent='';
				var length=data.rows.length;
				var caozuoc="<a class='group messageupdate_btn' href='javascript:void(0);'>信息修改</a>"
					+"<a class='group reset_btn' href='javascript:void(0); '>密码重置</a>"
					+"<a class='group cancel_btn' href='javascript:void(0);'>注销账号</a>";
				var caozuoc2="<a class='group messageupdate_btn' href='javascript:;'>信息修改</a>"
					+"<a class='group reset_btn' href='javascript:void(0); '>密码重置</a>"
					+"<a class='group cancel_btn2' href='javascript:void(0);'>启用账号</a>";
				for(var i=0;i<length;i++){
					if(data.rows[i].STATUS == 1){
						var state = '已启用';
						tableContent+="<tr><td>"+data.rows[i].RN
						+"</td><td>"+data.rows[i].ACCOUNT
						+"</td><td>"+data.rows[i].NAME
						+"</td><td>"+data.rows[i].ROLE_NAME
						+"</td><td>"+data.rows[i].ADD_TIME
						+"</td><td>"+state
						+"</td><td>"+caozuoc
						+"</td></tr>";
					}
					if(data.rows[i].STATUS == 0){
						var state = '已注销';
						tableContent+="<tr><td>"+data.rows[i].RN
						+"</td><td>"+data.rows[i].ACCOUNT
						+"</td><td>"+data.rows[i].NAME
						+"</td><td>"+data.rows[i].ROLE_NAME
						+"</td><td>"+data.rows[i].ADD_TIME
						+"</td><td>"+state
						+"</td><td>"+caozuoc2
						+"</td></tr>";
					}
					
				}
				$("#ActionShowTable").html(tableContent);
				//密码重置
				$(".reset_btn").click(function(){
					var index = $(this).parents("tr").index("#ActionShowTable tr");
					var account_temp=(data.rows[index].ACCOUNT==null?'':data.rows[index].ACCOUNT);
					console.log(account_temp);
					$("#account_temp").val(account_temp);
					$("#myalert").modal("show");
				});
				//注销账号
				$(".cancel_btn2").click(function(){
					var index = $(this).parents("tr").index("#ActionShowTable tr");
					var account_temp=(data.rows[index].ACCOUNT==null?'':data.rows[index].ACCOUNT);
					console.log(account_temp);
					$("#account_temp").val(account_temp);
					cancel_method(account_temp,1);
				});
				//启用账号
				$(".cancel_btn").click(function(){
					var index = $(this).parents("tr").index("#ActionShowTable tr");
					var account_temp=(data.rows[index].ACCOUNT==null?'':data.rows[index].ACCOUNT);
					console.log(account_temp);
					$("#account_temp").val(account_temp);
					cancel_method(account_temp,0);	
				});
				//修改信息
				$(".messageupdate_btn").click(function(){
					var index = $(this).parents("tr").index("#ActionShowTable tr");
					var account_temp=(data.rows[index].ACCOUNT==null?'':data.rows[index].ACCOUNT);
					console.log(account_temp);
					$("#account_temp").val(account_temp);
					update_method(account_temp);
				});
			},
			error : function(data){
				console.log(data)
			}
		});
}
function toSpecficPage(page) {
	submit(page);
}

function toInputPage() {
	var inputPage = $("#inputPageIndex").val();
	submit(inputPage);
}
</script>
</body>
</html>